<template>
	<view class="container" >
		<view class="status_bar">
			<view style="margin-left: 4%;" @tap="goBack()"><u-icon name="arrow-leftward" size='24' /></u-icon></view>
			<view style="margin-left: -50upx; font-weight: bold;">个人信息</view>
			<view style="margin-right: 30upx;" @tap="tosetInformation(itemArr)"><u-icon name="more-dot-fill"
					size="24"></u-icon></view>
		</view>
		<view class="head flex-row">
			<view class="flex-row">
				<image v-if="user.face" :src="user.face" class="face"></image>
				<image v-else src="../../static/img/face.png" class="face"></image>
				<view class="info-box">
					<view class="info-name">{{itemArr.nickname}}</view>
					<view class="info-num">账号:<span style="color: #666666;">{{itemArr.user_uid}}</span></view>
				</view>
			</view>
		</view>

		<textarea disabled="true" v-model="message_item.message.ex1" placeholder="请输入内容"
			style="margin-left: 10px;width: calc(100% - 20px);height: 100px;padding: 10px;"></textarea>

		<!-- <view class="chat-btn" @tap="toDetail(itemArr)">发起聊天</view> -->
		<view class="chat-btn" @tap="took(itemArr)">同意</view>
		<view class="chat-btn" @tap="tono(itemArr)">拒绝</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userId: uni.getStorageSync('userId') || '',
				startX: 0, // 触摸开始的X坐标
				endX: 0, // 触摸结束的X坐标
				threshold: 50, // 设置滑动多少距离后触发返回
				value2: true,
				user: {},
				lableValue: '',
				itemArr: '',
				ex1: ',',
				user_uid: '',

				message_item: {},

			}
		},
		onLoad(options) {
			console.log(options.user_uid)
			if (options.message_item) {
				this.message_item = JSON.parse(options.message_item)
			}
			console.log(this.message_item)
			this.user_uid = options.user_uid
			this.getfriendlist(options.user_uid)
		},
		onShow() {
			uni.$on('update', function(data) {
				//console.log('监听到事件来自 update ，携带参数 msg 为：' + data);
				this.lableValue = data;
				console.log(this.lableValue, 333)
			})
			
			

		},
		methods: {
			// 获取信息
			getfriendlist(id) {
				//  
				const newDataObj = {
					"use_mail": "0", // "1"表示用好友的 mail 地址查找，否则表示用好友的 uid 查找
					"friend_mail": "", // 用户或好友的 mail 地址
					"friend_uid": id, // 用户或好友的 uid
					"my_uid": uni.getStorageSync('user_uid')
				};
				const newDataJsonStr = JSON.stringify(newDataObj)
				const requestData = {
					"processorId": '1008',
					"jobDispatchId": '3',
					"actionId": '8',
					// "token":uni.getStorageSync('token'), 
					"token": "123123123123",
					"newData": newDataJsonStr
				};
				const requestDataJsonStr = JSON.stringify(requestData);
				uni.request({
					url: 'http://chat.zwsmcn.com:8090/rest_post',
					header: {
						'content-type': 'application/json'
					},
					data: requestDataJsonStr,
					method: 'POST',
					success: res => {
						console.log(JSON.parse(res.data.returnValue))
						// uni.hideLoading()
						this.itemArr = JSON.parse(res.data.returnValue)
						//  const updateInfoStr = JSON.stringify(res.data.returnValue);
						//   console.log(updateInfoStr);
						//  const updateInfoObj = JSON.parse(updateInfoStr);
						//  console.log(updateInfoObj);
						// console.log(JSON.parse(res.data.returnValue).new_uid);


						console.log(this.itemArr)
					},
					fail: res => {
						console.log(res);
					}
				});
			},
			took() {
				console.log('took')
				const newDataObj = {
					"srcUserUid": this.user_uid, // "1"表示用好友的 mail 地址查找，否则表示用好友的 uid 查找
					"localUserUid": uni.getStorageSync('user_uid'), // 用户或好友的 mail 地址
					"localUserNickName": uni.getStorageSync('nickname'), // 用户或好友的 uid
				};
				const newDataJsonStr = JSON.stringify(newDataObj)
				const requestData = {
					"processorId": '1008',
					"jobDispatchId": '3',
					"actionId": '25',
					// "token":uni.getStorageSync('token'), 
					"token": "123123123123",
					"newData": newDataJsonStr
				};
				const requestDataJsonStr = JSON.stringify(requestData);
				uni.request({
					url: 'http://chat.zwsmcn.com:8090/rest_post',
					header: {
						'content-type': 'application/json'
					},
					data: requestData, // requestDataJsonStr,
					method: 'POST',
					success: res => {
						console.log(res)
						// console.log(JSON.parse(res.data.returnValue))
						if (res.data.success == true) {
							let message_z = this.message_item.message;
							message_z.btn_status = 1;

							let dataContent_str = JSON.stringify(message_z);

							console.log(dataContent_str);
							console.log(this.message_item.fp);
							// del_flag = 1,
							let data = `dataContent = '${dataContent_str}'`;
							let where = `(fp = '${this.message_item.fp}')`
							// 修改表数据 DB.updateTableData(表名, 要修改的列名=修改后列值, 修改条件的列名, 修改条件的列值)
							this.DB.updateTableData("chat" + uni.getStorageSync("user_uid"), data, where)
								.then(res => {
									console.log(res);
								})
								.catch(error => {
									console.log("修改失败", error);
								});

							uni.navigateBack({
								delta: 2
							});
						}
					},
					fail: res => {
						console.log(res);
					}
				});
			},
			tono() {
				console.log('tono')
				const newDataObj = {
					"srcUserUid": this.user_uid, // "1"表示用好友的 mail 地址查找，否则表示用好友的 uid 查找
					"localUserUid": uni.getStorageSync('user_uid'), // 用户或好友的 mail 地址
					"localUserNickName": uni.getStorageSync('nickname'), // 用户或好友的 uid
				};
				const newDataJsonStr = JSON.stringify(newDataObj)
				const requestData = {
					"processorId": '1008',
					"jobDispatchId": '3',
					"actionId": '26',
					// "token":uni.getStorageSync('token'), 
					"token": "123123123123",
					"newData": newDataJsonStr
				};
				const requestDataJsonStr = JSON.stringify(requestData);
				uni.request({
					url: 'http://chat.zwsmcn.com:8090/rest_post',
					header: {
						'content-type': 'application/json'
					},
					data: requestData, // requestDataJsonStr,
					method: 'POST',
					success: res => {
						console.log(res)
						// console.log(JSON.parse(res.data.returnValue))
						if (res.data.success == true) {
							let message_z = this.message_item.message;
							message_z.btn_status = 2;

							let dataContent_str = JSON.stringify(message_z);
							console.log(dataContent_str);
							console.log(this.message_item.fp);

							let data = `del_flag = 1 , dataContent = '${dataContent_str}'`;
							let where = `(fp = '${this.message_item.fp}')`
							// 修改表数据 DB.updateTableData(表名, 要修改的列名=修改后列值, 修改条件的列名, 修改条件的列值)
							this.DB.updateTableData("chat" + uni.getStorageSync("user_uid"), data, where)
								.then(res => {
									console.log(res);
								})
								.catch(error => {
									console.log("修改失败", error);
								});

							uni.navigateBack({
								delta: 2
							});
						}
					},
					fail: res => {
						console.log(res);
					}
				});
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},


			// 详情
			toDetail(item) {
				this.$api.globalData = item;
				uni.setStorageSync('globalData', this.$api.globalData)
				this.toPage('/pages/index/index');
				// this.toPage('/pages/index/index?groupId=' + JSON.stringify(item));
			},
			// 更多信息
			towhatsup(item) {
				this.toPage('/pages/contacts/informationMore?groupId=' + JSON.stringify(item));
			},
			tosetInformation(item) {
				console.log(item);
				this.toPage('/pages/contacts/setInformation?groupId=' + JSON.stringify(item));
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		overflow: hidden;
	}

	.box {
		font-size: 12px;
		line-height: 36px;
		margin-left: 20px;
	}

	.container {
		width: 100%;
		height: 100%;
		background: #f4f7fc;
	}

	.status_bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 90upx;
		background: #fff;
	}

	.status_bar,
	.head {
		background-color: #fff;
		height: 160upx;
		padding-bottom: 60upx;

		.face {
			width: 160upx;
			height: 160upx;
			border-radius: 10upx;
		}

		.info-name {
			font-size: 40upx;
			font-weight: bold;
		}

		.info-num {
			padding: 2upx 0upx;
			border-radius: 30upx;
			margin-top: 21upx;
			color: #5d5d5d;
		}

		.copybtns {
			color: #4457a4;
			margin-top: 21upx;
		}

		.info-box {
			margin-left: 30upx;
		}
	}

	.shop-box {
		background-color: #fff;
		padding: 0upx 40upx;
		color: #2e2e2e;
		font-weight: 300;
		margin-top: 14upx;
		margin-bottom: 14upx;

		.con-shop {
			height: 100upx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}

	.chat-btn {
		background-color: #fff;
		text-align: center;
		color: #2f6dc2;
		font-weight: 300;
		padding: 36upx;
		border-bottom: solid 1px #f0f0f0;
	}
</style>